package com.ycz.springcloud.controller;/*
 @author ycz
 @date 2021-08-24-21:09  
*/

import com.ycz.springcloud.common.Result;
import com.ycz.springcloud.domain.BusCustomer;
import com.ycz.springcloud.query.BusCustomerQuery;
import com.ycz.springcloud.vo.SysUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/consumer/customer")
public class CustomerController {

    @Autowired
    private RestTemplate restTemplate;
    /**
     * REST_URL 的地址
     */
    private static final String REST_URL="http://CAR-PROVIDER-8001";


    @RequestMapping("/page.do")
    public Map<String, Object> page(BusCustomerQuery query,Integer page,Integer limit){
        query.setPage((page-1)*10);
        System.out.println(query);
        ResponseEntity<Map> mapResponseEntity=restTemplate.postForEntity(
                REST_URL+"/customer/page.do",query,Map.class
        );
        System.out.println(mapResponseEntity.getBody());
        List<SysUserVo> sysUserVos= (List<SysUserVo>) mapResponseEntity.getBody().get("data");
        //  List pageList= PageUtil.startPage(sysUserVos,page,limit);
        // 传过来的count，数据库查询到的条数
        Integer total= (Integer) mapResponseEntity.getBody().get("count");
        Map<String, Object> map2 = new HashMap<>();
        map2.put("code",200);
        map2.put("msg","操作成功");
        map2.put("list",sysUserVos);
        map2.put("total",total);
        return map2;
    }



}
